﻿using System;

namespace SlamCms.DomainEvents
{
	public static class DomainEventsManager
    { 
		public static IEventDispatcher Dispatcher { get; set; }

		static DomainEventsManager()
		{
			Dispatcher = new DefaultEventDispatcher();
		}

		public static void AddHandler<T>(Action<EventContext<T>> handler) where T : IDomainEvent
		{
			Dispatcher.AddHandler(handler);
		}

		public static void AddHandler<T>(IDomainEventHandler<T> handler) where T : IDomainEvent
		{
			Dispatcher.AddHandler(new Action<EventContext<T>>(handler.Handle));
		}

		public static void ClearHandlers()
		{
			Dispatcher.ClearHandlers();
		}

		public static void Raise<T>(T domainEvent) where T : IDomainEvent
		{
			Dispatcher.Dispatch(domainEvent);
		}
    } 
}
